# coding:utf-8

"""
<features></features>
"""

def _none_or_bool(val):
    if val is None:
        return val;
    return bool(val);

class DomainFeatures:
    _dumpxml_xpath = "/domain/features"
    def __init__(self):
        self._acpi = True
        self._apic = True
        self._pae = True
        
    def get_acpi(self):
        return self._acpi
    def set_acpi(self, val):
        self._acpi = _none_or_bool(val)
    acpi = property(get_acpi, set_acpi)

    def get_apic(self):
        return self._apic
    def set_apic(self, val):
        self._apic = _none_or_bool(val)
    apic = property(get_apic, set_apic);

    def get_pae(self):
        return self._pae
    def set_pae(self, val):
        self._pae = _none_or_bool(val)
    pae = property(get_pae, set_pae);

    def __setitem__(self, attr, val):
        return setattr(self, attr, val)
    def __getitem__(self, attr):
        return getattr(self, attr)
    def __delitem__(self, attr):
        return setattr(self, attr, None)


    def get_xml_config(self, defaults=None):
        if not defaults:
            defaults = {}
        ret = ""

        feature_xml = ""
        if self.acpi or (self.acpi is None and defaults.get("acpi")):
            feature_xml += "        <acpi/>\n"
        if self.apic or (self.apic is None and defaults.get("apic")):
            feature_xml += "        <apic/>\n"
        if self.pae or (self.pae is None and defaults.get("pae")):
            feature_xml += "        <pae/>\n"

        if feature_xml:
            ret += "    <features>\n"
            ret += "%s" % feature_xml
            ret += "    </features>"

        return ret
